﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;

public partial class cms_FactList : System.Web.UI.Page
{
    private int TypeId = 0;
    private DBClass db = new DBClass();

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            LoadData();
        }
    }

    private void LoadData()
    {
        ddlType.DataSource = db.GetAllType();
        ddlType.DataBind();
        ddlType.Items.Insert(0, new ListItem("Select", "0"));
        LoadGridview();
    }

    private void LoadGridview()
    {
        grvFactList.DataSource = db.GetListFactListByTypeId(TypeId);
        grvFactList.DataBind();
    }

    protected void grvFactList_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        if (e.CommandName == "Delete")
        {
            db.DeleteFactList(Convert.ToInt32(e.CommandArgument));
        }
        Response.Redirect("FactList.aspx");
    }
    protected void ddlType_SelectedIndexChanged(object sender, EventArgs e)
    {
        Int32.TryParse(ddlType.SelectedValue, out TypeId);
        LoadGridview();
    }
}